﻿/* mvcForum
 * Copyright (C) 2010-2011 Steen F. Tøttrup
 * http://mvcforum.org/
 */

using System;
using System.ComponentModel.DataAnnotations;

namespace mvcForum.Core {

	/// <summary>
	/// This class represent the timestamp of when a user last viewed a forum.
	/// </summary>
	public class ForumTrack {
		public ForumTrack() { }
		public ForumTrack(Forum forum, ForumUser user) {
			this.Forum = forum;
			this.ForumUser = user;
			this.LastViewed = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
		}

		public virtual void Viewed() {
			this.LastViewed = DateTime.UtcNow;
		}

		#region Properties
		/// <summary>
		/// The Id of the forum track.
		/// </summary>
		public Int32 Id { get; set; }
		private DateTime lastViewed;
		/// <summary>
		/// The timestamp indicating when the user last viewed the forum.
		/// </summary>
		[Required]
		public DateTime LastViewed {
			get {
				return this.lastViewed;
			}
			set {
				this.lastViewed = value.Handle();
			}
		}
		/// <summary>
		/// The forum tracked.
		/// </summary>
		[Required]
		public Int32 ForumId { get;set;}
		public virtual Forum Forum { get; set; }
		/// <summary>
		/// The user tracked.
		/// </summary>
		[Required]
		public Int32 ForumUserId { get; set; }
		public virtual ForumUser ForumUser { get; set; }
		#endregion
	}
}